//
//  ServiceRequest.m
//  gongwei-ios
//
//  Created by xiaoxiachuanqi on 2020/1/22.
//  Copyright © 2020 gongwei-mac. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AbstractServiceRequest.h"
#import "Guid.h"
#import "../serialize/Serializer.h"

@implementation AbstractServiceRequest
@synthesize id = _id;
@synthesize serviceName = _serviceName;
@synthesize entityUrl = _entityUrl;
@synthesize entityId = _entityId;
@synthesize methodName = _methodName;
@synthesize parameterValues = _parameterValues;

-(void)fillId {
    if(![self getId]) {
        Guid * guid = [Guid makeNew];
        self.id = [guid toString];
    }
}

-(NSString *)getId
{
    return self.id;
}

-(void)setId:(NSString *)newId
{
    _id = newId;
}

-(void)setServiceName:(NSString *)serviceName {
    _serviceName = serviceName;
}

-(NSString *)getServiceName {
    return self.serviceName;
}

-(void) setMethodName:(NSString *)methodName {
    _methodName = methodName;
}

-(NSString *) getMethodName {
    return self.methodName;
}

-(void) setParameterValues:(NSMutableArray *)parameterValues {
    _parameterValues = parameterValues;
}

-(NSMutableArray *)getParameterValues {
    return self.parameterValues;
}

-(void)setEntityUrl:(NSString *)entityUrl {
    _entityUrl = entityUrl;
}

- (NSString *)getEntityUrl {
    return self.entityUrl;
}

-(void)setEntityId:(long)entityId {
    _entityId = entityId;
}

-(long)getEntityId {
    return self.entityId;
}

-(void)fillFromDictionary:(NSDictionary *)dictionary {
    
}

-(NSMutableDictionary *)parseToDictionary: (BOOL) withTag {
    NSLog(@" === parse dictionary ===");
    NSMutableDictionary *dictionary = [super parseToDictionary: withTag];
    
    NSLog(@"%@", dictionary == nil ? @"yes" : @"no");
    if (self.id != nil) {
        [dictionary setObject:self.id forKey: @"id"];
    }
    
    if (self.serviceName != nil)
    {
        [dictionary setObject:self.serviceName forKey:@"serviceName"];
    }
    
    if (self.entityUrl != nil)
    {
        [dictionary setObject:self.entityUrl forKey:@"entityUrl"];
    }
    
    if (self.entityId)
    {
      [dictionary setObject:[NSNumber numberWithLong: self.entityId] forKey:@"entityId"];
    }
    
    if (self.methodName != nil)
    {
        [dictionary setObject:self.methodName forKey:@"methodName"];
    }
    
    
    if (self.parameterValues != nil)
    {
        unsigned long count = [_parameterValues count];
        unsigned long i;
        NSMutableArray *array0 = [NSMutableArray array];
        for (i = 0; i < count; i ++)
        {
            [array0 addObject:[Serializer parseObjectToData:[_parameterValues objectAtIndex:i] withJsonTagType:JTT_CLASS]];
        }
        [dictionary setObject:array0 forKey:@"parameterValues"];
    }
    
    return dictionary;
}
@end


